/** @file               sw_file.h
 *  @copyright          Copyright (C) 2006-2026 flyfish (tenggui_fu@126.com)
 *  @brief              This file is part of the swallow library
 *  @author             $Author: Thinkpad $
 *  @version            $Rev: 405 $
 *  @date               $Date: 2016-12-27 16:48:50 +0800 (周二, 27 12月 2016) $
 */
#ifndef __SW_FILE_H__
#define __SW_FILE_H__

#ifdef __cplusplus
extern "C" {
#endif

#ifdef WIN32
typedef HANDLE SW_FILE;
#define SW_INVALID_FILE (SW_FILE)INVALID_HANDLE_VALUE
#else
typedef int SW_FILE;
#define SW_INVALID_FILE (SW_FILE)(-1)
#endif

typedef enum _SW_OPEN_FLAG
{
    SW_OF_RDONLY,
    SW_OF_WRONLY,
    SW_OF_RDWR
}SW_OPEN_FLAG;

typedef enum _SW_WRITE_FLAG
{
    SW_WF_NORMAL,
    SW_WF_TRUNC,
    SW_WF_APPEND
}SW_WRITE_FLAG;

typedef enum _SW_SEEK_FROM
{
    SW_SF_SET,
    SW_SF_CUR,
    SW_SF_END
}SW_SEEK_FROM;

typedef enum _SW_FILE_MODE
{
    SW_FM_XOTH,
    SW_FM_WOTH,
    SW_FM_ROTH,
    SW_FM_XGRP,
    SW_FM_WGRP,
    SW_FM_RGRP,
    SW_FM_XUSR,
    SW_FM_WUSR,
    SW_FM_RUSR,
    SW_FM_NUM
}SW_FILE_MODE;

SW_API SW_RET SW_InitFileAPI(SW_VOID);
SW_API SW_RET SW_RunFileAPI(SW_VOID);
SW_API SW_RET SW_StopFileAPI(SW_VOID);
SW_API SW_RET SW_ExitFileAPI(SW_VOID);
SW_API SW_FILE SW_OpenFile(const SW_CHAR *pFileName, SW_OPEN_FLAG openFlag, SW_WRITE_FLAG wrFlag, SW_BOOL nonBlock);
SW_API SW_FILE SW_OpenFileEx(const SW_CHAR *pFileName, SW_OPEN_FLAG openFlag, SW_WRITE_FLAG wrFlag, SW_BOOL nonBlock, SW_UINT32 mode, SW_BOOL sync);
SW_API SW_RET SW_CloseFile(SW_FILE fd);
SW_API SW_UINT32 SW_ReadFile(SW_FILE fd, SW_VOID *pBuf, SW_UINT32 bufLen);
SW_API SW_UINT32 SW_ReadFileN(SW_FILE fd, SW_VOID *pBuf, SW_UINT32 bufLen);
SW_API SW_UINT32 SW_WriteFile(SW_FILE fd, const SW_VOID *pBuf, SW_UINT32 bufLen);
SW_API SW_UINT32 SW_WriteFileN(SW_FILE fd, const SW_VOID *pBuf, SW_UINT32 bufLen);
SW_API SW_BOOL SW_FileExists(const SW_CHAR *pFileName);
SW_API SW_UINT64 SW_GetFileLen(SW_FILE fd);
SW_API SW_RET SW_SeekFile(SW_FILE fd, SW_INT32 offset, SW_SEEK_FROM from);
SW_API SW_RET SW_GetFileBaseName(const SW_CHAR *pFileName, SW_CHAR *pBaseName, SW_UINT32 baseNameLen);
SW_API SW_RET SW_GetFileDirName(const SW_CHAR *pFileName, SW_CHAR *pDirName, SW_UINT32 dirNameLen);
SW_API SW_RET SW_DeleteFile(const SW_CHAR *pFileName);
SW_API SW_CMP SW_FileCmp(const SW_CHAR *pFileName1, const SW_CHAR *pFileName2);
SW_API SW_RET SW_CanonicalizePath(const SW_CHAR *pPath, SW_CHAR *pNewPath, SW_UINT32 newPathLen);
SW_API SW_RET SW_CanonicalizePathSelf(SW_CHAR *pPath);
SW_API SW_RET SW_ConcatPath(const SW_CHAR *pPath1, const SW_CHAR *pPath2, SW_CHAR *pNewPath, SW_UINT32 newPathLen);
SW_API SW_BOOL SW_IsFullPath(const SW_CHAR *pPath);
SW_API SW_RET SW_GetFullPath(const SW_CHAR *pPath, SW_CHAR *pFullPath, SW_UINT32 fullPathLen);
SW_API SW_RET SW_GetFullPathEx(const SW_CHAR *pPath, const SW_CHAR *pRefPath, SW_CHAR *pFullPath, SW_UINT32 fullPathLen);
SW_API SW_RET SW_GetCmdFullPath(const SW_CHAR *pCmdName, SW_CHAR *pFullPath, SW_UINT32 fullPathLen);
SW_API SW_RET SW_GetCmdFullPathEx(const SW_CHAR *pCmdName, const SW_CHAR *pRefPath, SW_CHAR *pFullPath, SW_UINT32 fullPathLen);
SW_API SW_RET SW_CopyFile(const SW_CHAR *pSrcFileName, const SW_CHAR *pNewFileName);
SW_API SW_RET SW_CreateSymbolLink(const SW_CHAR *pSrcFileName, const SW_CHAR *pSymbolFileName);

#ifndef SW_V_DISABLE_CMDSERVER
SW_API SW_RET SW_CmdCat(const SW_CHAR *pFileName);
#endif

#ifdef __cplusplus
}
#endif

#endif

